<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改商品信息')" />
    <th:block th:include="include :: datetimepicker-css" />
    <style>
        .spinner-buttons {
            display: inline-block;
            width: 100%;
            position: relative;
        }
        .spinner-buttons input {
            padding-right: 60px;
        }
        .spinner-buttons .btn-group-vertical {
            position: absolute;
            right: 0;
            top: 0;
            height: 34px;
            width: 30px;
        }
        .spinner-buttons .btn-group-vertical .btn {
            height: 17px;
            padding: 0 6px;
            font-size: 12px;
            line-height: 17px;
        }
    </style>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-product-edit" th:object="${baseProduct}">
            <input name="productId" th:field="*{productId}" type="hidden">
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">商品编号：</label>
                    <div class="col-sm-8">
                        <input name="productCode" th:field="*{productCode}" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">商品名称：</label>
                    <div class="col-sm-8">
                        <input name="productName" th:field="*{productName}" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">规格：</label>
                    <div class="col-sm-8">
                        <input name="specification" th:field="*{specification}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">单价：</label>
                    <div class="col-sm-8">
                        <input name="unitPrice" th:field="*{unitPrice}" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">数量：</label>
                    <div class="col-sm-8">
                        <div class="spinner-buttons">
                            <input name="quantity" th:field="*{quantity}" class="form-control" type="number" min="0" required>
                            <div class="btn-group-vertical">
                                <button type="button" class="btn btn-default btn-xs spinner-up">
                                    <i class="fa fa-chevron-up"></i>
                                </button>
                                <button type="button" class="btn btn-default btn-xs spinner-down">
                                    <i class="fa fa-chevron-down"></i>
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">单位：</label>
                    <div class="col-sm-8">
                        <select name="unit" class="form-control" th:with="type=${@dict.getType('product_unit')}">
                            <option value="">请选择</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictLabel}" th:selected="${dict.dictLabel == baseProduct.unit}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">商品类别：</label>
                    <div class="col-sm-8">
                        <select name="categoryId" class="form-control" th:with="type=${@dict.getType('product_category')}">
                            <option value="">请选择</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:selected="${dict.dictValue == baseProduct.categoryId}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">商品状态：</label>
                    <div class="col-sm-8">
                        <select name="status" class="form-control" th:with="type=${@dict.getType('product_status')}">
                            <option value="">请选择</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictLabel}" th:selected="${dict.dictLabel == baseProduct.status}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">品牌：</label>
                    <div class="col-sm-8">
                        <select name="brand" class="form-control" th:with="type=${@dict.getType('product_brand')}">
                            <option value="">请选择</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictLabel}" th:selected="${dict.dictLabel == baseProduct.brand}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">来源：</label>
                    <div class="col-sm-8">
                        <select name="source" class="form-control" th:with="type=${@dict.getType('product_source')}">
                            <option value="">请选择</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictLabel}" th:selected="${dict.dictLabel == baseProduct.source}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">备注：</label>
                    <div class="col-sm-8">
                        <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">创建者：</label>
                    <div class="col-sm-8">
                        <input name="createdBy" th:field="*{createdBy}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">创建时间：</label>
                    <div class="col-sm-8">
                        <div class="input-group date">
                            <input name="createdTime" th:value="${#dates.format(baseProduct.createdTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">更新者：</label>
                    <div class="col-sm-8">
                        <input name="updatedBy" th:field="*{updatedBy}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">更新时间：</label>
                    <div class="col-sm-8">
                        <div class="input-group date">
                            <input name="updatedTime" th:value="${#dates.format(baseProduct.updatedTime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "basedata/product";
        $("#form-product-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-product-edit').serialize());
            }
        }

        $("input[name='createdTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='updatedTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
        
        // 数量微调器的处理
        $(".spinner-up").on("click", function() {
            var input = $(this).closest(".spinner-buttons").find("input");
            var value = parseInt(input.val()) || 0;
            input.val(value + 1);
        });
        
        $(".spinner-down").on("click", function() {
            var input = $(this).closest(".spinner-buttons").find("input");
            var value = parseInt(input.val()) || 0;
            if (value > 0) {
                input.val(value - 1);
            }
        });
    </script>
</body>
</html>